package statistics;

import java.util.Random;


public class BinomialDistribution extends Distribution{

    protected double p;
    protected int n;
    
    public BinomialDistribution( int n , double p, Random random ){
        this.p = p;
        this.n = n;
        this.random = random;
 
    }
            

    public double expectation() {
       return n*p;
    }


    public double variance() {
        return n*p*(1-p);
    }


    public double nextRandom() {
        int sum=0;
        for(int i=1; i<=n; i++){
            double U = random.nextDouble();
            if(U<=p)
                sum = sum+1;
        }
        return sum;
        
    }
    
    
}